package sorttest;

import java.util.Arrays;

public class QuickSort {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int[] array = new int[] { 11, 66, 0, 55, 22, 32 };

		quicksort(array, 0, array.length - 1);

		System.out.println(Arrays.toString(array));

	}

	public static void quicksort(int[] array, int left, int right) {
		int i, j;
		i = left;
		j = right;

		int pivot = array[(i + j) / 2];
		int temp;

		do {
			while (array[i] < pivot && i < right) {
				i++;
			}

			while (array[j] > pivot && j > left) {
				j--;
			}

			if (i <= j) {
				temp = array[i];
				array[i] = array[j];
				array[j] = temp;

				i++;
				j--;
			}

		} while (i <= j);

		if (i < right) {
			quicksort(array, i, right);
		}

		if (j > left) {
			quicksort(array, left, j);
		}

	}
}
